package com.netease.nim.uikit.session.activity.Evaluate;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;

import com.netease.nim.uikit.MV.EduActivity;
import com.netease.nim.uikit.R;


/**
 * Created by Administrator on 2016/4/14.
 */
public class EvaluateActivity extends EduActivity implements EvaluateView {

    private TextView mTvPoint;
    private EditText mEtEvaluate;

    private EvaluatePresenter presenter;
    private String hosId = "", remark = "", recId = "";

    private CheckBox[] checkBoxes;
    private CheckBox cbone, cbtwo, cbthree, cbfour, cbfive;
    private int index = 0;
    private String userid;
    private String token;

    public static void start(Context context, String hosId, String recId) {
        Intent intent = new Intent();
        intent.putExtra("hosId", hosId);
        intent.putExtra("recId", recId);
        context.startActivity(intent);
    }

    @Override
    public void init() {
        initview();

        initdata();
    }

    private void initdata() {
        hosId = getIntent().getStringExtra("hosId");
        recId = getIntent().getStringExtra("recId");
        presenter = new EvaluatePresenter(this, this);
    }

    private void initview() {
        mTvPoint = (TextView) findViewById(R.id.tv_point);
        mEtEvaluate = (EditText) findViewById(R.id.et_evaluate);
        findViewById(R.id.btn_confirm).setOnClickListener(this);
        findViewById(R.id.reL_all).setOnClickListener(this);
        cbone = (CheckBox) findViewById(R.id.cb_one);
        cbtwo = (CheckBox) findViewById(R.id.cb_two);
        cbthree = (CheckBox) findViewById(R.id.cb_three);
        cbfour = (CheckBox) findViewById(R.id.cb_four);
        cbfive = (CheckBox) findViewById(R.id.cb_five);
        checkBoxes = new CheckBox[]{cbone, cbtwo, cbthree, cbfour, cbfive};

        cbone.setOnClickListener(this);
        cbtwo.setOnClickListener(this);
        cbthree.setOnClickListener(this);
        cbfour.setOnClickListener(this);
        cbfive.setOnClickListener(this);
    }

    @Override
    public void onClickEvent(View view) {
        int i = view.getId();
        if (i == R.id.btn_confirm) {
            remark = mEtEvaluate.getText().toString();
            presenter.submitevaluate(hosId, (index + 1), remark, recId,userid,token);

        } else if (i == R.id.reL_all) {
        } else if (i == R.id.cb_one) {
            index = 0;
            seleted(0);

        } else if (i == R.id.cb_two) {
            index = 1;
            seleted(1);

        } else if (i == R.id.cb_three) {
            index = 2;
            seleted(2);

        } else if (i == R.id.cb_four) {
            index = 3;
            seleted(3);

        } else if (i == R.id.cb_five) {
            index = 4;
            seleted(4);

        }
    }

    private void seleted(int i) {
        for (int j = 0; j <= 4; j++) {
            checkBoxes[j].setChecked(false);
        }
        for (int j = 0; j <= i; j++) {
            checkBoxes[j].setChecked(true);
        }
        if (i == 4) {
            mTvPoint.setText("满意");
        } else if (i == 3) {
            mTvPoint.setText("一般");
        } else {
            mTvPoint.setText("不满意");
        }

    }

    @Override
    public void setContentLayout() {
        setContentView(R.layout.activity_evaluate);
        userid = getIntent().getStringExtra("userid");
        token = getIntent().getStringExtra("token");
    }

    @Override
    public void submitsucced() {
        showToastMessage("成功");
        setResult(RESULT_OK);
        finish();
    }

    @Override
    public void submitfail() {
        showToastMessage("失败");
    }
}
